// src/store/apiSlice/consultApiSlice.ts
import { apiSlice } from "@store/apiSlice/index";

export const consultApiSlice = apiSlice.injectEndpoints({
    endpoints: (builder) => ({
        // 获取问诊预付款信息
        consultPreData: builder.query<ConsultOrderPreDataResponse, ConsultOrderPreParams>({
            query: (params) => ({ url: "/patient/consult/order/pre", params }),
        }),
        // 生成问诊订单
        createConsultOrder: builder.mutation<HealthResponse<{ id: string }>, PartialConsult>({
            query: (body) => ({
                url: "/patient/consult/order",
                method: "POST",
                body,
            }),
        }),
        // 获取订单支付地址
        payConsultOrder: builder.mutation<
            HealthResponse<{ payUrl: string }>,
            // 0 微信支付 1 支付宝 2 云闪付
            { paymentMethod: 0 | 1 | 2; orderId: string; payCallback: string }
            >({
            query: (body) => ({ url: "/patient/consult/pay", method: "POST", body }),
        }),
        // 获取订单详情
        orderDetail: builder.query<ConsultOrderResponse, string>({
            query: (orderId) => ({
                url: "/patient/consult/order/detail",
                params: { orderId },
            }),
        }),
        //获取处方单
        prescription :builder.query<HealthResponse<{url:string;id:string}>,string>({
            query: (id) => ({ url: `/patient/consult/prescription/${id}` }),

        })
    }),
});

export const { useConsultPreDataQuery ,useCreateConsultOrderMutation, usePayConsultOrderMutation,useOrderDetailQuery,useLazyPrescriptionQuery } = consultApiSlice;